package com.xpgk.mvc.organizationLevel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.log.Log;
import com.xpgk.dto.RenderBean;
import com.xpgk.dto.ZtreeNode;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.right.Right;

public class OrganLevelController extends BaseController {

	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(OrganLevelController.class);

	private OrganLevelService organLevelService;

	private RenderBean result = new RenderBean();

	private String pIds; // 上级节点ds
	private String name; // 节点名称
	private int orderId; // 排序号
	private int level;// 级别
	/**
	 * 是否验证
	 */
	public static final String privilegess = "1";// 是否验证
	/**
	 * 状态
	 */
	public static final String status = "1";// 状态

	public void index() {
		setAttr("curLevelIds", getCUser().getOrganization().getStr(Organization.column_levelIds));
		render("organLevel.html");
	}

	/**
	 * levelTree节点数据
	 */
	public void levelTreeData() {
		List<ZtreeNode> nodeList = organLevelService.childNodeData(getCxt(), ids, getCUserOrganIds());
		renderJson(nodeList);
	}

	/**
	 * rightTree节点数据
	 */
	public void rightTreeData() {
		String curLevelIds = getCUser().getOrganization().getStr(Organization.column_levelIds);
		String levelIds = getPara("levelIds", curLevelIds);
		if(getCUserOrganIds().equals(Organization.system)){
			Map<String, Object> queryParam = new HashMap<String, Object>();
			queryParam.put(Right.column_ids, ids);
			queryParam.put(Right.column_parentids, pIds);
			queryParam.put(Right.column_name, name);
			queryParam.put(Right.column_orderid, orderId);
			queryParam.put(Right.column_level, level);
			queryParam.put(Right.column_privilegess, privilegess);
			queryParam.put(Right.column_status, status);
			queryParam.put("levelIds", levelIds);
			List<ZtreeNode> nodeList = organLevelService.rightChildNodeDataSystem(getCxt(), queryParam, levelIds);
			renderJson(nodeList);
		}else{
			List<ZtreeNode> nodeList = organLevelService.rightChildNodeData(getCxt(), levelIds, curLevelIds, ids);
			renderJson(nodeList);
		}
	}

	/**
	 * 添加层级权限
	 */
	public void addLevelRight() {
		String curLevelIds = getCUser().getOrganization().getStr(Organization.column_levelIds);
		String levelIds = getPara("levelIds");
		result = organLevelService.addLevelRight(ids, levelIds, result, curLevelIds);
		renderJson(result);
	}

	/**
	 * 删除层级权限
	 */
	public void delLevelRight() {
		String curLevelIds = getCUser().getOrganization().getStr(Organization.column_levelIds);
		String levelIds = getPara("levelIds");
		result = organLevelService.delLevelRight(ids, levelIds, result, curLevelIds);
		renderJson(result);
	}

}
